#include<iostream>
#include<vector>
using namespace std;
/*
给定钢条的价格与长度对应表，p[i],i为长度，求一根长为i的钢条如何切割使得价格最高
对于该问题转化为求解子问题，钢条分隔后一端进行切割另一端不进行切割，且该分隔的次数也要循环进行
Rn = max(pi+Rn-i)
*/
vector<int> p = {1,5,8,9,10,17,17,20,24,30};
int max(int a,int b)
{
    if(a>b)
        return a;
    else 
        return b;
}
int bottom_up_cut(int n)
{
    //存放局部最优解的dp数组
    vector<int> r(n+1);
    for(int i=1;i<=n;i++)
    {       
        int q = -1;
        //该循环用于求出最优子解，其中r[0] = 0,代表不切割
        for(int j=1;j<=i;j++)
            q = max(q,p[j-1]+r[i-j]);
        r[i] = q;
        cout<<r[i]<<endl;
    }
    int result = r[n];
    return result;
}   

int main()
{
    //对应1-10
    cout<<"enter a number between 1 and 10:"<<endl;
    int n;
    cin>>n;
    cout<<"the max price is:"<<bottom_up_cut(n)<<endl;
    return 0;
}